package com.itcast.framdemo.service.impl;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itcast.framdemo.DTO.EmpDTO;
import com.itcast.framdemo.entity.Emp;
import com.itcast.framdemo.mapper.EmpMapper;
import com.itcast.framdemo.service.IEmpService;
import com.itcast.framdemo.vo.EmpVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * <p>
 * 员工表 服务实现类
 * </p>
 *
 * @author wangcong
 * @since 2024-12-10
 */
@Service
public class EmpServiceImpl extends ServiceImpl<EmpMapper, Emp> implements IEmpService {

    @Autowired
    private EmpMapper empMapper;


    @Override
    public EmpVO login(EmpDTO empDTO) {
        QueryWrapper<Emp> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("username",empDTO.getUsername()).eq("password",empDTO.getPassword());
        Emp emp = empMapper.selectOne(queryWrapper);
        EmpVO empVO = new EmpVO();
        if (empVO != null){
            BeanUtils.copyProperties(emp,empVO);
            HashMap<String, Object> map = new HashMap<>();
            map.put("username",empVO.getUsername());
            map.put("password",empDTO.getPassword());
            //设置token
//            String token = JWTUtils.createToken(map);
//            empVO.setToken(token);
        }
        return empVO;
    }

    /**
     * 分页查询员工数据
     */
    @Override
    public IPage<Emp> getPageList() {
            QueryWrapper<Emp> queryWrapper = new QueryWrapper<>();
            IPage<Emp> page = new Page<>();
            page.setCurrent(1);
            page.setSize(3);
            return empMapper.selectPage(page, queryWrapper);
    }
}
